let id = 0 



class Dep {
    static target = null
    constructor() {
        this.subs = []
        this.id = id++
    }

    addSub(sub) {
        this.subs.push(sub)
    }

    removeSub(sub) {
        const { id } = sub
        this.subs = this.subs.filter(item => item.id !== id)
    }

    depend() {
        if (Dep.target) Dep.target.addDeps(this)
    }

    notify() {
        this.subs.forEach(item => item.update())
    }

}


window.Dep = Dep